<HTML>
<HEAD>
	<meta charset="utf-8" />
	<title>网关配置</title>
</HEAD>
<BODY>
	<h1 align="center">建科博瑞：网关配置</h1><br><br>
	<div align="right">
		<input type="submit" name="reboot" value="重启" />
		<a href="sql/sql.html">点表配置</a>
	</div>
<form id="form1" name="form1" method="post" action="proc/web2json">
<fieldset>
	<legend>配置</legend>
		配置来源：
	<select name="config" id="select" onchange="b();">
	  <option value="0">数据库</option>
	  <option value="1">服务器</option>
	</select>
</fieldset>
<fieldset id="station">
	<legend>数据库主站配置</legend>
	<table id="station_table" name="station_table" style="background-color:#eeeeee;" bordercolor="#aaaaaa" border="1" cellpadding="0" cellpadding="2" width="100%">
		<thead>
			<tr>
				<th>ID</th>
				<th>MAC</th>
				<th>端口号</th>
				<th>对时标志</th>
				<th>IP</th>
				<th>帐号</th>
				<th>密码</th>
			</tr>
		</thead>
		<tbody contenteditable='true'>
			<tr>



				<td>0</td><td>fsf</td><td>1883</td><td>1</td><td>192.168.0.1</td><td>admin</td><td>123456</td>
			</tr>
		</tbody>
	</table>
</fieldset>
<fieldset id="sys_set">
	<legend>网关配置</legend>
	<table id="sys_table" name="station_table" style="background-color:#eeeeee;" bordercolor="#aaaaaa" border="1" cellpadding="0" cellpadding="2" width="100%">
		<thead>
			<tr>
				<th>id</th>
				<th>父id</th>
				<th>命令</th>
				<th>数据处理方式</th>
			</tr>
		</thead>
		<tbody contenteditable='true'>
			<tr>


				<td>1</td><td>1</td><td>ls</td><td>ls</td>
			</tr>
		</tbody>
	</table>
	<input id="add" type="button" onClick="addRow();" style="font-size:16px;" value="新增(+)"/>
	<input type="button" name="Submit22" value="重置" onclick="window.location.reload()" />

</fieldset>
<input id="JSONText" name="json_station"  style="display:none" type="text" value=""/>
<input id="sys_input" name="json_sys_set"  style="display:none" type="text" value=""/>
<div align="center">
	<button id="save">提交</button>
</div>
</form>
</BODY>
<!--
-->
<script LANGUAGE="JAVASCRIPT">
save.onclick = function(){
	var table = document.getElementById('station_table');
	var myform = document.getElementById('form1');
	var contractAll = [];
	var rows=table.rows;
	for(var i=0;i<rows.length;i++){
		var contractList = [];
		var cells=rows[i].cells;
		for(var j=0;j<cells.length;j++){   //--循环所有的列
			contractList.push(cells[j].innerHTML);
		}
		contractAll.push(contractList);
	}
	alert(JSON.stringify(contractAll));
	document.getElementById('JSONText').value = JSON.stringify(contractAll);
	var sys_table = document.getElementById('sys_table');
	var contract_sys = [];
	var rows=sys_table.rows;
	for(var i=0;i<rows.length;i++){
		var sysList = [];
		var cells=rows[i].cells;
		for(var j=0;j<cells.length;j++){   //--循环所有的列
			sysList.push(cells[j].innerHTML);
		}
		contract_sys.push(sysList);
	}
	alert(JSON.stringify(contract_sys));
	document.getElementById('sys_input').value = JSON.stringify(contract_sys);
	myform.submit();
}
iIndex = 0; //试验一下加了int类型定义后如何？？？
var i= 1;
function getIndex(){
	iIndex = event.srcElement.parentElement.parentElement.rowIndex;
	return iIndex;
}
function delRow(iPos){
	document.all.sys_table.deleteRow(iPos);
	i--;
}
function addRow(iPos){
	var otr=sys_table.insertRow(i + 1);
	var ocell=otr.insertCell(0);
	ocell.innerHTML=""+i+"";
	var ocell=otr.insertCell(1);
	ocell.innerHTML="<input type=button onclick=delRow(getIndex()) value='删除"+i+"'>";
	i++;
}

</SCRIPT>
</HTML>
 

